package com.yuanian.ecsplus.template;

import com.yuanian.ecsplus.bean.CommonModel;
import com.yuanian.ecsplus.model.entity.BaseModel;

import java.util.List;

/**
 * service的基类,继承此类拥有下面的通用方法
 * @param <T>
 */
public abstract class ServiceTemplate<T extends BaseModel> extends BaseTemplate {

    protected void insert(T t) {
        t.insert();
    }

    protected void update(T t) {
        t.update();
    }

    protected void delete(T t) {
        t.delete();
    }

    protected void issue(T t) {
        t.issue();
    }

    protected T selectOne(String objectId) {
        Class clz = getClazz();
        CommonModel<T> commonModel = new CommonModel<>(clz);
        return commonModel.selectByObjectId(objectId);
    }

    protected void batchSave(List<T> list) {
        Class clz = getClazz();
        CommonModel<T> commonModel = new CommonModel<>(clz);
        commonModel.batchSave(list);
    }

    protected List<T> batchInsert(List<T> list) {
        Class clz = getClazz();
        CommonModel<T> commonModel = new CommonModel<>(clz);
        commonModel.batchInsert(list);
        return list;
    }

}
